package com.zwface.demo.function.login;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;

import com.blankj.utilcode.util.ColorUtils;
import com.qmuiteam.qmui.widget.tab.QMUIBasicTabSegment;
import com.qmuiteam.qmui.widget.tab.QMUITabBuilder;
import com.zwface.demo.R;
import com.zwface.demo.base.BaseActivity;
import com.zwface.demo.comm.comm;
import com.zwface.demo.databinding.ActivityRegisterBinding;
import com.zwface.demo.function.login.event.RegisterEvent;
import com.zwface.demo.function.login.mvvm.LoginViewModel;
import com.zwface.demo.function.web.WebActivity;
import com.zwface.demo.utils.CountDownTimerUtils;

import org.greenrobot.eventbus.Subscribe;

import androidx.lifecycle.ViewModelProviders;


public class RegisterActivity extends BaseActivity<ActivityRegisterBinding> implements View.OnClickListener {

    private LoginViewModel viewModel;
    @Override
    public int onLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    public Boolean onSetEventBus() {
        return true;
    }

    @Override
    public void onInitViewDataBinding(ActivityRegisterBinding binding) {
        super.onInitViewDataBinding(binding);
        viewModel = ViewModelProviders.of(this).get(LoginViewModel.class);
        binding.setData(viewModel);
    }

    @Override
    public void onInitData(Bundle savedInstanceState) {
        super.onInitData(savedInstanceState);
        QMUITabBuilder tabBuilder = binding.tabSegment.tabBuilder().setGravity(Gravity.CENTER);
        binding.tabSegment.addTab(tabBuilder.setText("学生").build(context));
        binding.tabSegment.addTab(tabBuilder.setText("教师").build(context));
        binding.tabSegment.selectTab(0);
        binding.tabSegment.notifyDataChanged();
    }

    @Override
    public void onInitListener() {
        super.onInitListener();
        binding.tvLogin.setOnClickListener(this);
        binding.btnRegister.setOnClickListener(this);
        binding.tvAgreement.setOnClickListener(this);
        binding.tvAgreement2.setOnClickListener(this);

        binding.tabSegment.addOnTabSelectedListener(new QMUIBasicTabSegment.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int index) {
                switch (index){
                    case 0:
                        viewModel.type.set(comm.USER_TYPE_STU);
                        break;
                    case 1:
                        viewModel.type.set(comm.USER_TYPE_TEA);
                        break;
                }
            }

            @Override
            public void onTabUnselected(int index) {

            }

            @Override
            public void onTabReselected(int index) {

            }

            @Override
            public void onDoubleTap(int index) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.tv_login:
                finish();
                break;
            case R.id.btn_register:
                viewModel.register();
                break;
            case R.id.tv_agreement:
                WebActivity.start(context,"用户协议", comm.AGREEMENT_TYPE_REGISTER);
                break;
            case R.id.tv_agreement2:
                WebActivity.start(context,"隐私政策",comm.AGREEMENT_TYPE_PRIVATE_POLICY);
                break;
        }
    }

    @Subscribe
    public void onRegisterEvent(RegisterEvent event){
    }
}
